package service

import (
	"context"
	"ruoyi-go-echo-ddd/internal/domain/model"
	"ruoyi-go-echo-ddd/internal/domain/repository"
	"ruoyi-go-echo-ddd/internal/infrastructure/http/request"
)

type SysDeptService struct {
	Repo repository.SysDeptRepository
}

func NewSysDeptService(repo repository.SysDeptRepository) *SysDeptService {
	return &SysDeptService{Repo: repo}
}

// Save 新增
func (s *SysDeptService) Save(ctx context.Context, dept *model.Dept) (*model.Dept, error) {
	deptReturn, err := s.Repo.Save(ctx, dept)
	if err != nil {
		return nil, err
	}
	return deptReturn, nil
}

// Update 更新
func (s *SysDeptService) Update(ctx context.Context, dept *model.Dept) (*model.Dept, error) {
	return s.Repo.Update(ctx, dept)
}

func (s *SysDeptService) SelectById(ctx context.Context, id int64) (*model.Dept, error) {
	return s.Repo.SelectById(ctx, id)
}

func (s *SysDeptService) CheckDept(ctx context.Context, deptId int64) (bool, error) {
	return s.Repo.CheckDept(ctx, deptId)
}

func (s *SysDeptService) BatchSave(ctx context.Context, list []*model.Dept) ([]int64, error) {
	return s.Repo.BatchSave(ctx, list)
}

func (s *SysDeptService) BatchSaveByList(ctx context.Context, list []*request.DeptInsert) ([]int64, error) {
	return s.Repo.BatchSaveByList(ctx, list)
}

func (s *SysDeptService) SelectDeptList(ctx context.Context, param *request.DeptPageParam) ([]*model.Dept, error) {
	return s.Repo.SelectDeptList(ctx, param)
}

func (s *SysDeptService) SelectPage(ctx context.Context, param *request.DeptPageParam) ([]*model.Dept, int64, int64, error) {
	return s.Repo.SelectPage(ctx, param)
}

func (s *SysDeptService) BatchDelete(ctx context.Context, ids []any) (int64, error) {
	return s.Repo.BatchDelete(ctx, ids)
}

func (s *SysDeptService) SelectListByDept(ctx context.Context, dept *model.Dept) ([]*model.Dept, error) {
	return s.Repo.SelectListByDept(ctx, dept)
}

func (s *SysDeptService) BuildDeptTree(list []*model.Dept) ([]*model.Dept, error) {
	return s.Repo.BuildDeptTree(list)
}

func (s *SysDeptService) BuildDeptTreeSelect(list []*model.Dept) []*model.TreeSelect {
	return s.Repo.BuildDeptTreeSelect(list)
}

func (s *SysDeptService) SelectListByRoleId(ctx context.Context, roleId int64) ([]int64, error) {
	return s.Repo.SelectListByRoleId(ctx, roleId)
}

func (s *SysDeptService) SelectAll(ctx context.Context) ([]*model.Dept, error) {
	return s.Repo.SelectAll(ctx)
}
